@extends('admin.main')

@section('body')
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>商品列表</h2>
    </div>
    <div class="cf">
        <div class="fl">
            @if(plat_identify() == 'account')<a class="btn" href="{{urlPlat('single','getGoodsAdd')}}">新 增</a>
                <button class="btn list_sort" url="{{urlPlat('single','getGoodsSort',['shop_id'=>request('shop_id')])}}">排序</button>
                <button class="btn ajax-post" url="{{urlPlat('single','anyChangeGoodsStatus',['method'=>'up',['shop_id'=>request('shop_id')]])}}"
                        target-form="ids">上 架
                </button>
                <button class="btn ajax-post" url="{{urlPlat('single','anyChangeGoodsStatus',['method'=>'down',['shop_id'=>request('shop_id')]])}}"
                        target-form="ids">下 架
                </button>
            @endif
            {{--<button class="btn ajax-post confirm" url="{{urlPlat('shop','anyChangeStatus',['method'=>'delete'])}}"--}}
            {{--target-form="ids">删 除--}}
            {{--</button>--}}
        </div>

        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <input type="text" name="keyword" class="search-input" value="{{request('keyword')}}"
                   placeholder="请输入商品名称">
            <a class="sch-btn" href="javascript:;" id="search" url="{{urlPlat('single','getGoods')}}"><i
                        class="btn-search"></i></a>
        </div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table class="">
            <thead>
            <tr>
                @if(plat_identify() == 'account')<th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>@endif
                <th class="">商品图片</th>
                <th class="">商品名称</th>
                <th class="">商品价格</th>
                <th class="">商品库存</th>
                <th class="">状态</th>
                <th class="">创建时间</th>
                <th class="">更新时间</th>
                @if(plat_identify() == 'account')<th class="">操作</th>@endif
            </tr>
            </thead>
            <tbody>
            @if(count($rows['data']))
                @foreach($rows['data'] as $v)
                    <tr>
                        @if(plat_identify() == 'account')<td><input class="ids" type="checkbox" name="ids[]" value="{{$v['id']}}"/></td>@endif
                        {{--<td>{{$v['id']}}</td>--}}
                        <td>
                            <img src="/uploads/goods/imgs/{{$v['admin_id']}}/{{$v['goods_id']}}_1_{{$mini}}.{{$ext}}?{{time()}}"/>
                        </td>
                        <td>{{$v['goods_name']}}</td>
                        <td>{{$v['goods_price']}}</td>
                        <td>{{$v['goods_num']}}</td>
                        <td style="color: @if($v['status'] > 0) blue @elseif($v['status'] < 0) red @endif">{{$v['status_text']}}</td>
                        <td><span>{{$v['addtime'] ? date('Y-m-d H:i:s',$v['addtime']) : '--'}}</span></td>
                        <td><span>{{$v['updated_at']}}</span></td>
                        @if(plat_identify() == 'account')
                            <td>
                                {{--<a href="javascript:;" onclick="showInfo({{$v['id']}})">详情</a>--}}
                                <a title="入库" href="{{urlPlat('single','getGoodsStock',['id'=>$v['id']])}}">入库</a>
                                <a title="入库" href="javascript:;" onclick="showStockList({{$v['id']}})">入库记录</a>
                                <a title="编辑"
                                   href="{{urlPlat('single','getGoodsEdit',['id'=>$v['goods_id'],'shop_id'=>$v['shop_id']])}}">编辑</a>
                                @if($v['status'] == 1)
                                    <a href="{{urlPlat('single','anyChangeGoodsStatus',['method'=>'down','ids'=>$v['id'],'shop_id'=>$v['shop_id']])}}"
                                       class="ajax-get" style="color:red">下架</a>
                                @else
                                    <a href="{{urlPlat('single','anyChangeGoodsStatus',['method'=>'up','ids'=>$v['id'],'shop_id'=>$v['shop_id']])}}"
                                       class="ajax-get" style="color:blue">上架</a>
                                @endif
                            </td>
                        @endif
                    </tr>
                @endforeach
            @else
                <td colspan="12" class="text-center"> aOh! 暂时还没有内容!</td>
            @endif
            </tbody>
        </table>
    </div>
    <div class="page">
        @if($rows['last_page']>1)
            <div>
                @if($rows['prev_page_url'])
                    <a class="prev" href="{{$rows['prev_page_url']}}">&lt;&lt;</a>
                @endif
                @if(count($rows['pageNoList']))
                    @foreach($rows['pageNoList'] as $v)
                        @if($rows['current_page'] == $v)
                            <span class="current">{{$v}}</span>
                        @else
                            <a class="num" href="{{urlPlat('single','getGoods',['page'=>$v])}}">{{$v}}</a>
                        @endif
                    @endforeach
                @endif
                @if($rows['next_page_url'])
                    <a class="next" href="{{$rows['next_page_url']}}">&gt;&gt;</a>
                @endif
                <span class="rows">共 {{$rows['total']}} 条记录</span>
            </div>
        @endif
    </div>
@endsection

@section('script')

    <script type="text/javascript">

        //搜索功能
        $("#search").click(function () {
            var url = $(this).attr('url');
            var shop_id = $("#sch-sort-txt").attr("data");
            var query = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            query = query.replace(/^&/g, '');
            if (shop_id != '') {
                query = 'shop_id=' + shop_id + "&" + query;
            }
            if (url.indexOf('?') > 0) {
                url += '&' + query;
            } else {
                url += '?' + query;
            }
            window.location.href = url;
        });

        /* 状态搜索子菜单 */
        $(".search-form").find(".drop-down").hover(function () {
            $("#sub-sch-menu").removeClass("hidden");
        }, function () {
            $("#sub-sch-menu").addClass("hidden");
        });
        $("#sub-sch-menu li").find("a").each(function () {
            $(this).click(function () {
                var text = $(this).text();
                $("#sch-sort-txt").text(text).attr("data", $(this).attr("value"));
                $("#sub-sch-menu").addClass("hidden");
                window.location.href = '{{urlPlat('single','getGoods')}}';
            })
        });
        //点击排序
        $('.list_sort').click(function(){
            var url = $(this).attr('url');
            var ids = $('.ids:checked');
            var param = '';
            if(ids.length > 0){
                var str = new Array();
                ids.each(function(){
                    str.push($(this).val());
                });
                param = str.join(',');
            }

            if(url != undefined && url != ''){
                window.location.href = url + '&ids=' + param;
            }
        });

        function showStockList(id) {
            url = "{{urlPlat('single','getStockList')}}?id=" + id;
            layer.open({
                type: 2,
                title: '入库记录',
                area: ['85%','70%'],
                fixed: false,
                content: url
            })
        }

    </script>
@endsection
